<template>
  <el-table :data="petList" stripe style="width: 100%">
    <el-table-column prop="ptitle" label="标题" #default="scope">
      <el-link @click="toDetail(scope.row.pid)">{{ scope.row.ptitle }}</el-link>
    </el-table-column>
    <el-table-column prop="psubhead" label="副标题"/>
    <el-table-column prop="createdate" label="发布时间" width="170px"/>
    <el-table-column prop="pname" label="联系人"/>
    <el-table-column prop="piphone" label="手机号"/>
    <el-table-column prop="pstatus" label="状态" #default="scope">
      {{
        scope.row.pstatus === 1 ? '等待审核' : scope.row.pstatus === 2 ? '正在显示' : scope.row.pstatus === 3 ? '已被领养'
            : '其他'
      }}
    </el-table-column>
    <el-table-column fixed="right" label="操作" width="150">
      <template #default="scope">
        <el-button @click="adopted(scope.row.pid)" type="success" size="small"
                   round v-if="scope.row.pstatus === 2">已领养
        </el-button>
      </template>
    </el-table-column>
  </el-table>
  <!--  分页-->
  <div class="pageBox">
    <el-pagination
        :page-size="5"
        small
        background
        layout="prev, pager, next"
        :total="total"
        class="mt-4"
        v-model:current-page="nowPage"
        @update:current-page="getData"
    />
  </div>
</template>

<script>
import doThis from "@/api/getData";

export default {
  name: "UserPet",
  data() {
    return {
      petList: [],
      nowPage: 1,
      total: 0,
    }
  },
  methods: {
    adopted(pid) {
      if (confirm("已被领养后将不会再显示，确定要操作码？")){
        doThis.doGet("/pet/findUser", {pid: pid, pstatus: 3}).then(res => {
          if (res.code === "0") {
            this.getData()
          }
        })
      }

    },
    getData(){
      doThis.doGet("/pet/findUser", {pageNum: this.nowPage}).then(res => {
        console.log(res)
        this.petList = res.data.list
        this.total = res.data.count
      })
    },
    toDetail(pid){
this.$router.push("/front/petDetail/"+pid)
    },
  },
  mounted() {
   this.getData()
  }
}
</script>

<style>

</style>